﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Order
{
    public class Order:IComparable
    {
        public int OrderID { get; set; }
        public string CustomerID { get; set; }
        public int Sum
        {
            get
            {
                int a = 0;
                foreach (OrderDetail temp in this.OrderDetailsList)
                {
                    a += temp.ProductNumber * temp.Value;
                }
                return a;
            }
        }
        public List<OrderDetail> OrderDetailsList = new List<OrderDetail>();
        public Order(int orderID, string customerID, List<OrderDetail> list)
        {
            this.OrderID = orderID;
            this.CustomerID = customerID;
            foreach (OrderDetail temp in list)
            {
                this.OrderDetailsList.Add(temp);
            }
        }
        public Order() { }
      
        public override string ToString()
        {
            return "ID：" + OrderID + " 总价：" + Sum + " 客户：" + CustomerID;
        }
        public override bool Equals(object obj)
        {
            Order m = obj as Order;
            return m.OrderID == this.OrderID && m != null;
        }
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
        public int CompareTo(object obj)
        {
            Order m = obj as Order;
            if (m == null) throw new Exception("输入错误！！！");
            return this.OrderID.CompareTo(m.OrderID);
        }
    }
}
